/* -*- mode: C++; indent-tabs-mode: nil; -*-
 *
 * This file is a part of LEMON, a generic C++ optimization library.
 *
 * Copyright (C) 2003-2010
 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
 * (Egervary Research Group on Combinatorial Optimization, EGRES).
 *
 * Permission to use, modify and distribute this software is granted
 * provided that this copyright notice appears in all copies. For
 * precise terms see the accompanying LICENSE file.
 *
 * This software is provided "AS IS" with no warranty of any kind,
 * express or implied, and with no claim as to its suitability for any
 * purpose.
 *
 */

//#define LEMON_HAVE_GLPK
#include <iostream>
#include <lemon/lp.h>

using namespace lemon;

int main()
{
  // Create an instance of the default LP solver class
  // (it will represent an "empty" problem at first)
  Lp lp;

  // Add two columns (variables) to the problem
  Lp::Col w0 = lp.addCol();
  Lp::Col w1 = lp.addCol();
  Lp::Col w2 = lp.addCol();
  Lp::Col eps = lp.addCol();

  // Add rows (constraints) to the problem
  Lp::Constr cw1(-Lp::INF,w0,0);
  lp.addRow(w0 <= 0);
  lp.addRow(w1 <= 0);
  lp.addRow(w2 <= 0);
  lp.addRow(2+eps+w0+w1+w2 >=0);
  lp.addRow(1+w1+w2>=0);
  lp.addRow(-1-eps-w1>=0);
  lp.addRow(-1-eps-w0-w2>=0);
  lp.addRow(1+w0>=0);
  // Set lower and upper bounds for the columns (variables)
//  lp.colLowerBound(x1, 0);
//  lp.colUpperBound(x2, 10);
  
  // Specify the objective function
  lp.max();
  lp.obj(eps);
  
  // Solve the problem using the underlying LP solver
  lp.solve();

  // Print the results
  if (lp.primalType() == Lp::OPTIMAL) {
    std::cout << "Objective function value: " << lp.primal() << std::endl;
    std::cout << "w0 = " << lp.primal(w0) << std::endl;
    std::cout << "w1 = " << lp.primal(w1) << std::endl;
    std::cout << "w2 = " << lp.primal(w2) << std::endl;
    std::cout << "eps = " << lp.primal(eps) << std::endl;
  } else {
    std::cout << "Optimal solution not found." << std::endl;
  }

  return 0;
}
